{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SEGTRAX ATL10 read in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the functions from Amy's NSIDC DAAC notebook\n",
    "\n",
    "import requests\n",
    "import getpass\n",
    "import socket\n",
    "import json\n",
    "import zipfile\n",
    "import io\n",
    "import math\n",
    "import os\n",
    "import shutil\n",
    "import pprint\n",
    "import time\n",
    "import geopandas as gpd\n",
    "import matplotlib.pyplot as plt\n",
    "import fiona\n",
    "import h5py\n",
    "import re\n",
    "# To read KML files with geopandas, we will need to enable KML support in fiona (disabled by default)\n",
    "fiona.drvsupport.supported_drivers['LIBKML'] = 'rw'\n",
    "from shapely.geometry import Polygon, mapping\n",
    "from shapely.geometry.polygon import orient\n",
    "from statistics import mean\n",
    "from requests.auth import HTTPBasicAuth"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Accessing data from the NSIDC DAAC with the code from Amy's tutorial\n",
    "\n",
    "Need to generate a token to access the Earthdata login credentials and apply to future queries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Earthdata Login password: ·········\n"
     ]
    }
   ],
   "source": [
    "# Create a token\n",
    "# Earthdata Login credentials\n",
    "# Enter your Earthdata Login user name\n",
    "uid = 'davidbabb'\n",
    "# Enter your email address associated with your Earthdata Login account\n",
    "email = 'david.babb@umanitoba.ca'\n",
    "pswd = getpass.getpass('Earthdata Login password:')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0A5D25AF-2421-2A2A-B9B8-2955A319E87E\n"
     ]
    }
   ],
   "source": [
    "# Request token from Common Metadata Repository using Earthdata credentials\n",
    "token_api_url = 'https://cmr.earthdata.nasa.gov/legacy-services/rest/tokens'\n",
    "hostname = socket.gethostname()\n",
    "ip = socket.gethostbyname(hostname)\n",
    "\n",
    "data = {\n",
    "    'token': {\n",
    "        'username': uid,\n",
    "        'password': pswd,\n",
    "        'client_id': 'NSIDC_client_id',\n",
    "        'user_ip_address': ip\n",
    "    }\n",
    "}\n",
    "headers={'Accept': 'application/json'}\n",
    "response = requests.post(token_api_url, json=data, headers=headers)\n",
    "token = json.loads(response.content)['token']['id']\n",
    "print(token)\n",
    "#4351E4A7-9907-AEA1-82B3-FE2A36C88659"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Select the dataset of interest and queiry the available files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Input data set ID (e.g. ATL07) of interest here, also known as \"short name\".\n",
    "# ATL07 - Sea ice height - https://nsidc.org/data/atl07\n",
    "# ATL10 - Sea ice freeboard - https://nsidc.org/data/atl10\n",
    "\n",
    "short_name = 'ATL10'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Determine the number and size of granules available within a time range and location"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Collect the metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'feed': {'entry': [{'archive_center': 'NASA NSIDC DAAC',\n",
      "                     'associations': {'services': ['S1568899363-NSIDC_ECS',\n",
      "                                                   'S1613689509-NSIDC_ECS',\n",
      "                                                   'S1613669681-NSIDC_ECS']},\n",
      "                     'boxes': ['-90 -180 90 180'],\n",
      "                     'browse_flag': False,\n",
      "                     'coordinate_system': 'CARTESIAN',\n",
      "                     'data_center': 'NSIDC_ECS',\n",
      "                     'dataset_id': 'ATLAS/ICESat-2 L3A Sea Ice Freeboard V001',\n",
      "                     'has_formats': True,\n",
      "                     'has_spatial_subsetting': True,\n",
      "                     'has_temporal_subsetting': True,\n",
      "                     'has_transforms': False,\n",
      "                     'has_variables': True,\n",
      "                     'id': 'C1511851914-NSIDC_ECS',\n",
      "                     'links': [{'href': 'https://n5eil01u.ecs.nsidc.org/ATLAS/ATL10.001/',\n",
      "                                'hreflang': 'en-US',\n",
      "                                'length': '0.0KB',\n",
      "                                'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#'},\n",
      "                               {'href': 'http://nsidc.org/daac/subscriptions.html',\n",
      "                                'hreflang': 'en-US',\n",
      "                                'length': '0.0KB',\n",
      "                                'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#'},\n",
      "                               {'href': 'https://search.earthdata.nasa.gov/search/granules?p=C1511851914-NSIDC_ECS&m=-87.87967837686685!9.890967019347585!1!1!0!0%2C2&tl=1542476530!4!!&q=atl10&ok=atl10',\n",
      "                                'hreflang': 'en-US',\n",
      "                                'length': '0.0KB',\n",
      "                                'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#'},\n",
      "                               {'href': 'https://doi.org/10.5067/ATLAS/ATL10.001',\n",
      "                                'hreflang': 'en-US',\n",
      "                                'rel': 'http://esipfed.org/ns/fedsearch/1.1/metadata#'},\n",
      "                               {'href': 'https://doi.org/10.5067/ATLAS/ATL10.001',\n",
      "                                'hreflang': 'en-US',\n",
      "                                'rel': 'http://esipfed.org/ns/fedsearch/1.1/documentation#'}],\n",
      "                     'online_access_flag': True,\n",
      "                     'orbit_parameters': {'inclination_angle': '92.0',\n",
      "                                          'number_of_orbits': '1.0',\n",
      "                                          'period': '94.29',\n",
      "                                          'start_circular_latitude': '0.0',\n",
      "                                          'swath_width': '36.0'},\n",
      "                     'organizations': ['NASA NSIDC DAAC',\n",
      "                                       'NASA/GSFC/EOS/ESDIS'],\n",
      "                     'original_format': 'ISO19115',\n",
      "                     'processing_level_id': 'Level 3',\n",
      "                     'short_name': 'ATL10',\n",
      "                     'summary': 'This data set (ATL10) contains estimates of '\n",
      "                                'sea ice freeboard, calculated using three '\n",
      "                                'different approaches. Sea ice leads used to '\n",
      "                                'establish the reference sea surface and '\n",
      "                                'descriptive statistics used in the height '\n",
      "                                'estimates are also provided. The data were '\n",
      "                                'acquired by the Advanced Topographic Laser '\n",
      "                                'Altimeter System (ATLAS) instrument on board '\n",
      "                                'the Ice, Cloud and land Elevation Satellite-2 '\n",
      "                                '(ICESat-2) observatory.',\n",
      "                     'time_start': '2018-10-14T00:00:00.000Z',\n",
      "                     'title': 'ATLAS/ICESat-2 L3A Sea Ice Freeboard V001',\n",
      "                     'version_id': '001'}],\n",
      "          'id': 'https://cmr.earthdata.nasa.gov:443/search/collections.json?short_name=ATL10',\n",
      "          'title': 'ECHO dataset metadata',\n",
      "          'updated': '2019-06-20T23:31:36.714Z'}}\n"
     ]
    }
   ],
   "source": [
    "# Get json response from CMR collection metadata and print results. This provides high-level metadata on a data set or \"collection\", provide in json format.\n",
    "\n",
    "params = {\n",
    "    'short_name': short_name\n",
    "}\n",
    "\n",
    "cmr_collections_url = 'https://cmr.earthdata.nasa.gov/search/collections.json'\n",
    "response = requests.get(cmr_collections_url, params=params)\n",
    "results = json.loads(response.content)\n",
    "pprint.pprint(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There may be cases with various versions of the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "001\n"
     ]
    }
   ],
   "source": [
    "# Find all instances of 'version_id' in metadata and print most recent version number\n",
    "\n",
    "versions = [i['version_id'] for i in results['feed']['entry']]\n",
    "latest_version = max(versions)\n",
    "print(latest_version)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now set the temporal range to search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-11-01T00:00:00Z,2018-11-07T23:59:59Z\n"
     ]
    }
   ],
   "source": [
    "# Input temporal range \n",
    "\n",
    "# Input start date in yyyy-MM-dd format\n",
    "start_date = '2018-11-01'\n",
    "# Input start time in HH:mm:ss format\n",
    "start_time = '00:00:00'\n",
    "# Input end date in yyyy-MM-dd format\n",
    "end_date = '2018-11-07'\n",
    "# Input end time in HH:mm:ss format\n",
    "end_time = '23:59:59'\n",
    "\n",
    "temporal = start_date + 'T' + start_time + 'Z' + ',' + end_date + 'T' + end_time + 'Z'\n",
    "print(temporal)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now set the area of interest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### There are three different options\n",
    "\n",
    "    1) Bounding box \n",
    "    2) Polygon coordinate pairs\n",
    "    3) Spatial file (kml)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Input bounding box:\n",
    "# # Input lower left longitude in decimal degrees\n",
    "# LL_lon = '-95'\n",
    "# # Input lower left latitude in decimal degrees\n",
    "# LL_lat = '55'\n",
    "# # Input upper right longitude in decimal degrees\n",
    "# UR_lon = '-70'\n",
    "# # Input upper right latitude in decimal degrees\n",
    "# UR_lat = '65'\n",
    "\n",
    "# bounding_box = LL_lon + ',' + LL_lat + ',' + UR_lon + ',' + UR_lat\n",
    "# # aoi value used for CMR params below\n",
    "# aoi = '1'\n",
    "# print(bounding_box)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Polygon"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "130.0,65.0,180.0,65.0,180.0,88.0,130.0,88.0,130.0,65.0\n"
     ]
    }
   ],
   "source": [
    "# Create a list of polygon coordinate pairs\n",
    "\n",
    "#create list of x (longitude) values in decimal degrees\n",
    "x = [130.0,180.0,180.0,130.0,130.0]\n",
    "#create list of y (latitude) values in decimal degrees\n",
    "y = [65.0,65.0,88.0,88.0,65.0]\n",
    "xylist = list(zip(x, y))\n",
    "# Polygon points need to be provided in counter-clockwise order. The last point should match the first point to close the polygon. \n",
    "# Input polygon coordinates as comma separated values in longitude latitude order, i.e. lon1, lat1, lon2, lat2, lon3, lat3, and so on.\n",
    "polygon = ','.join(map(str, list(sum(xylist, ()))))\n",
    "print(polygon)\n",
    "\n",
    "# For the polygon method aoi=3\n",
    "aoi = 3\n",
    "\n",
    "\n",
    "# Get polygon bounds to be used as bounding box input\n",
    "# Create shapely Polygon object from x y list\n",
    "p = Polygon(tuple(xylist))\n",
    "# Extract the point values that define the perimeter of the polygon\n",
    "bounds = p.bounds\n",
    "bbox = ','.join(map(str, list(bounds)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "130.0,65.0,180.0,88.0\n"
     ]
    }
   ],
   "source": [
    "print(bbox)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %matplotlib inline\n",
    "\n",
    "# # Load \"Natural Earth” countries dataset, bundled with GeoPandas\n",
    "# world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n",
    "\n",
    "# # Overlay glacier outline\n",
    "# f, ax = plt.subplots(1, figsize=(12, 6))\n",
    "# world.plot(ax=ax, facecolor='lightgray', edgecolor='gray')\n",
    "# polygon.plot(ax=ax, cmap='Set2')\n",
    "# ax.set_ylim([0, 90])\n",
    "# ax.set_xlim([-180,0]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Now that we have our time and area defined we will create a dictionary to be applied to our search query below based on the spatial and temporal inputs defined above"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CMR search parameters:  {'short_name': 'ATL10', 'version': '001', 'temporal': '2018-11-01T00:00:00Z,2018-11-07T23:59:59Z', 'page_size': 100, 'page_num': 1, 'polygon': '130.0,65.0,180.0,65.0,180.0,88.0,130.0,88.0,130.0,65.0'}\n"
     ]
    }
   ],
   "source": [
    "#Create CMR parameters used for granule search. Modify params depending on bounding_box or polygon input.\n",
    "\n",
    "params = {\n",
    "'short_name': short_name,\n",
    "'version': latest_version,\n",
    "'temporal': temporal,\n",
    "'page_size': 100,\n",
    "'page_num': 1,\n",
    "'polygon': polygon,\n",
    "}\n",
    "\n",
    "print('CMR search parameters: ', params)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Input the parameter dictionary to the CMR granula search to query all granules that meet the criteria based on the granule metadata. Print the number of granules returned"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "93"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "granule_search_url = 'https://cmr.earthdata.nasa.gov/search/granules'\n",
    "\n",
    "granules = []\n",
    "while True:\n",
    "    response = requests.get(granule_search_url, params=params, headers=headers)\n",
    "    results = json.loads(response.content)\n",
    "\n",
    "    if len(results['feed']['entry']) == 0:\n",
    "        # Out of results, so break out of loop\n",
    "        break\n",
    "\n",
    "    # Collect results and increment page_num\n",
    "    granules.extend(results['feed']['entry'])\n",
    "    params['page_num'] += 1\n",
    "\n",
    "    \n",
    "# Get number of granules over my area and time of interest\n",
    "len(granules)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now query the average size of those granules (MB)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "81.48081187791828"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "granule_sizes = [float(granule['granule_size']) for granule in granules]\n",
    "\n",
    "# Average size of granules in MB\n",
    "mean(granule_sizes)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### As well as the total volume"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7577.715504646401"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Total volume in MB\n",
    "sum(granule_sizes)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Select the subsetting and reformatting sevrices enabled for your data set of interest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The NSIDC DAAC supports customization services on many of our NASA Earthdata mission collections. Reformatting and subsetting are available on all Level-2 and -3 ICESat-2 data sets. Let's discover the specific service options supported for this data set and select which of these services we want to request. \n",
    "\n",
    "We will start by querying the service capability to gather and select customization options."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://n5eil02u.ecs.nsidc.org/egi/capabilities/ATL10.001.xml\n"
     ]
    }
   ],
   "source": [
    "# Query service capability URL \n",
    "\n",
    "from xml.etree import ElementTree as ET\n",
    "\n",
    "capability_url = f'https://n5eil02u.ecs.nsidc.org/egi/capabilities/{short_name}.{latest_version}.xml'\n",
    "\n",
    "print(capability_url)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All of NSIDC's service endpoints are behind NASA Earthdata Login. We need to create a session to store cookies and pass Earthdata Login credentials to capabilities url."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create session to store cookie and pass credentials to capabilities url\n",
    "\n",
    "session = requests.session()\n",
    "s = session.get(capability_url)\n",
    "response = session.get(s.url,auth=(uid,pswd))\n",
    "\n",
    "root = ET.fromstring(response.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the service capability XML, we can collect lists with each service option to gather service information."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "# collect lists with each service option\n",
    "\n",
    "subagent = [subset_agent.attrib for subset_agent in root.iter('SubsetAgent')]\n",
    "\n",
    "# variable subsetting\n",
    "variables = [SubsetVariable.attrib for SubsetVariable in root.iter('SubsetVariable')]  \n",
    "variables_raw = [variables[i]['value'] for i in range(len(variables))]\n",
    "variables_join = [''.join(('/',v)) if v.startswith('/') == False else v for v in variables_raw] \n",
    "variable_vals = [v.replace(':', '/') for v in variables_join]\n",
    "\n",
    "# reformatting\n",
    "formats = [Format.attrib for Format in root.iter('Format')]\n",
    "format_vals = [formats[i]['value'] for i in range(len(formats))]\n",
    "format_vals.remove('')\n",
    "\n",
    "# reprojection only applicable on ICESat-2 L3B products, yet to be available. \n",
    "\n",
    "# reformatting options that support reprojection\n",
    "normalproj = [Projections.attrib for Projections in root.iter('Projections')]\n",
    "normalproj_vals = []\n",
    "normalproj_vals.append(normalproj[0]['normalProj'])\n",
    "format_proj = normalproj_vals[0].split(',')\n",
    "format_proj.remove('')\n",
    "format_proj.append('No reformatting')\n",
    "\n",
    "#reprojection options\n",
    "projections = [Projection.attrib for Projection in root.iter('Projection')]\n",
    "proj_vals = []\n",
    "for i in range(len(projections)):\n",
    "    if (projections[i]['value']) != 'NO_CHANGE' :\n",
    "        proj_vals.append(projections[i]['value'])\n",
    "        \n",
    "# reformatting options that do not support reprojection\n",
    "no_proj = [i for i in format_vals if i not in format_proj]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Let's confirm that subset services exist for our data set by reviewing the `subagent` list. If the list contains service information, we know that services are available. If not, we need to set the `agent` API parameter to `NO` to indicate that our request will bypass the subsetter. This will quickly send back the data \"natively\" without any customization applied."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'id': 'ICESAT2', 'spatialSubsetting': 'true', 'spatialSubsettingShapefile': 'true', 'temporalSubsetting': 'true', 'type': 'both', 'maxGransSyncRequest': '100', 'maxGransAsyncRequest': '2000'}]\n"
     ]
    }
   ],
   "source": [
    "print(subagent)\n",
    "if len(subagent) < 1 :\n",
    "    agent = 'NO'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-11-01T00:00:00,2018-11-07T23:59:59\n"
     ]
    }
   ],
   "source": [
    "# Temporal subsetting KVP\n",
    "\n",
    "timevar = start_date + 'T' + start_time + ',' + end_date + 'T' + end_time\n",
    "print(timevar)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Next, let's determine if variable subsetting is available by finding the length of the variable_vals lst we gathered from the capabilities URL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "609"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(variable_vals)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " We can view the entire list of variables if desired:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pprint.pprint(variable_vals)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But it's a long list so it may be best to enter a list of variables to subset our data. (Use the ATL10-data-dictionary-v001.pdf for reference)\n",
    "\n",
    "For this project we were only using 1 beam and for the first week of November. At that time ICESat-2 was flying in the backward orientation so \"gtl1\" is the strong beam.\n",
    "\n",
    "* Note that the satellite flipped on December 28, 2018 and switched gt1r to the strong beam. the satellite flips every 6 months. See the ICESat-2 documentation at NSIDC."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define the variables wanted\n",
    "coverage = '/ancillary_data/atlas_sdp_gps_epoch,\\\n",
    "/gt1l/freeboard_beam_segment/beam_fb_height,\\\n",
    "/gt1l/freeboard_beam_segment/beam_fb_length,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/longitude,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/latitude,\\\n",
    "/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,\\\n",
    "/orbit_info/cycle_number,\\\n",
    "/orbit_info/rgt,\\\n",
    "/orbit_info/orbit_number'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reference for the variables downloaded:\n",
    "-atlas_sdp_gps_epoch: The number of GPS Seconds between the GPS epoch (1980-01-06T00:00:00 UTC) and the ATLAS Standard Data Product (SDP) epoch (2018-01-01T00:00:00 UTS). Add this value to the delta time parameters to compute full gps_seconds (relative to the GPS epoch) for each data points. <br>\n",
    "\n",
    "/beam/freeboard_beam_segment <br>\n",
    "-beam_fb_height: Mean of the Freeboard heightsegments\n",
    "in freeboard beamsegment <br>\n",
    "-beam_fb_length: Length of freeboard beamsegment <br>\n",
    "\n",
    "/beam/freeboard_beam_segment/beam_freeboard <br>\n",
    "-beam_fb_confidence: Confidence level in the freeboard estimate <br>\n",
    "-beam_fb_height: Estimate of the freeboard height based on the beam h reference <br>\n",
    "-beam_fb_quailty_flag: Flag describing the quality of the results of the alongtrack fit. (1= height value is invalid; 1=ngrid_w < wlength/2; 2=ngrid_w >= wlength/2; 3=ngrid_dt < dtlength/2; 4=ngrid_dt >= dtlength/2; 5=ngrid_dt >= (dtlength2): where 1 is best and 5 is poor). <br>\n",
    "flag_values: -1, 1, 2, 3, 4, 5 <br>\n",
    "flag_meanings : invalid bes t high med low poor<br>\n",
    "-beam_fb_sigma: estimate of the sigma ( standard deviation) for each beam freeboard height <br>\n",
    "-delta_time: Number of GPS seconds since the ATLAS SDP epoch. The\n",
    "ATLAS Standard Data Products (SDP) epoch offset is defined within /ancillary_data/atlas_sdp_gps_epoch as the number of GPS seconds between the GPS epoch (19800106T00:00:00.000000Z UTC) and the ATLAS SDP epoch. By adding the offset contained within atlas_sdp_gps_epoch to delta time parameters, the time in gps_seconds relative to the GPS epoch can be computed. <br>\n",
    "-height_segment_id: Identifier of each height segment <br>\n",
    "-longitude: Longitude, WGS84, East=+,Lon of segment center <br>\n",
    "-latitude: Latitude, WGS84, North=+, Lat of segment center <br>\n",
    "-seg_dist_x: Alongtrack distance from the equator crossing to the\n",
    "segment center. <br>\n",
    "-cycle_number: A count of the number of exact repeats of this reference orbit. <br>\n",
    "\n",
    "orbit info <br>\n",
    "-rgt: The reference ground track (RGT) is the track on the earth\n",
    "at which a specified unit vector within the observatory is\n",
    "pointed. Under nominal operating conditions, there will be\n",
    "no data collected along the RGT, as the RGT is spanned by\n",
    "GT3 and GT4. During slews or offpointing,it is possible\n",
    "that ground tracks may intersect the RGT. The ICESat2\n",
    "mission has 1387 RGTs.<br>\n",
    "-orbit_number: Unique identifying number for each planned ICESat2\n",
    "orbit.\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Request the data from the NSIDC data access API"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### As described above, the API is structured as a URL with a base plus individual key-value-pairs (KVPs) separated by ‘&’. The base URL of the NSIDC API is:\n",
    "`https://n5eil02u.ecs.nsidc.org/egi/request`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Set NSIDC data access base URL\n",
    "base_url = 'https://n5eil02u.ecs.nsidc.org/egi/request'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Let's go over the configuration parameters:\n",
    "\n",
    "* `request_mode`\n",
    "* `page_size`\n",
    "* `page_num`\n",
    "\n",
    "`request_mode` is \"synchronous\" by default, meaning that the request relies on a direct, continous connection between you and the API endpoint. Outputs are directly downloaded, or \"streamed\" to your working directory. For this tutorial, we will set the request mode to asynchronous ('async'), which will allow concurrent requests to be queued and processed without the need for a continuous connection.\n",
    "\n",
    "**Use the streaming `request_mode` with caution: While it can be beneficial to stream outputs directly to your local directory, note that timeout errors can result depending on the size of the request, and your request will not be queued in the system if NSIDC is experiencing high request volume. For best performance, I recommend setting `page_size=1` to download individual outputs, which will eliminate extra time needed to zip outputs and will ensure faster processing times per request. An example streaming request loop is available at the bottom of the tutorial below. **\n",
    "\n",
    "Recall that we queried the total number and volume of granules prior to applying customization services. `page_size` and `page_num` can be used to adjust the number of granules per request up to a limit of 2000 granules for asynchronous, and 100 granules for synchronous (streaming). For now, let's select 10 granules to be processed in each zipped request. For ATL06, the granule size can exceed 100 MB so we want to choose a granule count that provides us with a reasonable zipped download size. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "# Set number of granules requested per order, which we will initially set to 10.\n",
    "page_size = 10\n",
    "\n",
    "#Determine number of pages basd on page_size and total granules. Loop requests by this value\n",
    "page_num = math.ceil(len(granules)/page_size)\n",
    "\n",
    "#Set request mode. \n",
    "request_mode = 'async'\n",
    "\n",
    "# Determine how many individual orders we will request based on the number of granules requested\n",
    "\n",
    "print(page_num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### If we were to create an API request based on our request parameters and submit into a web browser for example, here's what we end up with:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00:00:00Z,2018-11-07T23:59:59Z&time=2018-11-01T00:00:00,2018-11-07T23:59:59&polygon=130.0,65.0,180.0,65.0,180.0,88.0,130.0,88.0,130.0,65.0&Coverage=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number&request_mode=async&page_size=10&page_num=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb@umanitoba.ca\n"
     ]
    }
   ],
   "source": [
    "#Print API base URL + request parameters\n",
    "API_request = f'{base_url}?short_name={short_name}&version={latest_version}&temporal={temporal}&time={timevar}&polygon={polygon}&Coverage={coverage}&request_mode={request_mode}&page_size={page_size}&page_num={page_num}&token={token}&email={email}'\n",
    "print(API_request)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Define the parameters to use when searching for data on the NSIDC site. Each of these parameters has been defined above. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'short_name': 'ATL10', 'version': '001', 'temporal': '2018-11-01T00:00:00Z,2018-11-07T23:59:59Z', 'time': '2018-11-01T00:00:00,2018-11-07T23:59:59', 'polygon': '130.0,65.0,180.0,65.0,180.0,88.0,130.0,88.0,130.0,65.0', 'Coverage': '/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number', 'request_mode': 'async', 'page_size': 10, 'token': '0A5D25AF-2421-2A2A-B9B8-2955A319E87E', 'email': 'david.babb@umanitoba.ca', 'bbox': '130.0,65.0,180.0,88.0'}\n"
     ]
    }
   ],
   "source": [
    "subset_params = {\n",
    "    'short_name': short_name, \n",
    "    'version': latest_version, \n",
    "    'temporal': temporal, \n",
    "    'time': timevar, \n",
    "    'polygon': polygon, \n",
    "    'Coverage': coverage, \n",
    "    'request_mode': request_mode, \n",
    "    'page_size': page_size,  \n",
    "    'token': token, \n",
    "    'email': email,\n",
    "    'bbox': bbox\n",
    "    }\n",
    "print(subset_params)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Request Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Finally, we'll download the data directly to this notebook directory in a new Outputs folder. The progress of each order will be reported.\n",
    "\n",
    "We'll start by creating an output folder if the folder does not already exist."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = str(os.getcwd() + '/Outputs')\n",
    "if not os.path.exists(path):\n",
    "    os.mkdir(path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run our request loop with subsetting services applied using the polygon\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Order:  1\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=1\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320343</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161185346,SC:ATL10.001:161185896,SC:ATL10.001:161182802,SC:ATL10.001:161081600,SC:ATL10.001:161185349,SC:ATL10.001:161138413,SC:ATL10.001:161182786,SC:ATL10.001:161151705,SC:ATL10.001:161185240,SC:ATL10.001:161181989. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.105S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320343\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320343\n",
      "HTTP response from order response URL:  201\n",
      "Data request  1  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161185346:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161185896:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161138413:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161151705:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161181989:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.746S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320343.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 1 is complete.\n",
      "Order:  2\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=2\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320344</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161184155,SC:ATL10.001:161183891,SC:ATL10.001:161184150,SC:ATL10.001:161183758,SC:ATL10.001:161183830,SC:ATL10.001:161157327,SC:ATL10.001:161183898,SC:ATL10.001:161053169,SC:ATL10.001:161158002,SC:ATL10.001:161183896. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.102S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320344\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320344\n",
      "HTTP response from order response URL:  201\n",
      "Data request  2  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161183891:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161183830:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161158002:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.542S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320344.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 2 is complete.\n",
      "Order:  3\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=3\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320345</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161184281,SC:ATL10.001:161173633,SC:ATL10.001:161184176,SC:ATL10.001:161183734,SC:ATL10.001:161184173,SC:ATL10.001:161173645,SC:ATL10.001:161183783,SC:ATL10.001:161194358,SC:ATL10.001:161184167,SC:ATL10.001:161156884. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.100S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320345\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320345\n",
      "HTTP response from order response URL:  201\n",
      "Data request  3  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161184281:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161173633:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161183734:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161183783:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.623S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320345.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 3 is complete.\n",
      "Order:  4\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=4\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320346</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161200614,SC:ATL10.001:161058492,SC:ATL10.001:161184370,SC:ATL10.001:161184458,SC:ATL10.001:161185342,SC:ATL10.001:161143165,SC:ATL10.001:161184708,SC:ATL10.001:161156880,SC:ATL10.001:161157986,SC:ATL10.001:161148852. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.104S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320346\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320346\n",
      "HTTP response from order response URL:  201\n",
      "Data request  4  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161200614:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161184370:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161185342:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161143165:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161157986:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.431S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320346.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 4 is complete.\n",
      "Order:  5\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=5\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320347</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161148864,SC:ATL10.001:161061914,SC:ATL10.001:161156879,SC:ATL10.001:161184288,SC:ATL10.001:161194356,SC:ATL10.001:161184744,SC:ATL10.001:161185339,SC:ATL10.001:161191100,SC:ATL10.001:161201894,SC:ATL10.001:161184456. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.101S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320347\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320347\n",
      "HTTP response from order response URL:  201\n",
      "Data request  5  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161148864:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161194356:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161185339:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161201894:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161184456:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.714S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320347.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 5 is complete.\n",
      "Order:  6\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=6\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320348</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161184827,SC:ATL10.001:161185446,SC:ATL10.001:161185894,SC:ATL10.001:161146275,SC:ATL10.001:161185228,SC:ATL10.001:161185237,SC:ATL10.001:161184285,SC:ATL10.001:161185233,SC:ATL10.001:161186580,SC:ATL10.001:161184648. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.114S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320348\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320348\n",
      "HTTP response from order response URL:  201\n",
      "Data request  6  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161185446:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161185228:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161184648:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.692S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320348.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 6 is complete.\n",
      "Order:  7\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=7\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320349</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161185347,SC:ATL10.001:161110544,SC:ATL10.001:161152739,SC:ATL10.001:161183875,SC:ATL10.001:161202198,SC:ATL10.001:161150652,SC:ATL10.001:161184826,SC:ATL10.001:161110542,SC:ATL10.001:161151326,SC:ATL10.001:161182040. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.115S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320349\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320349\n",
      "HTTP response from order response URL:  201\n",
      "Data request  7  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161152739:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161183875:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161184826:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.610S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320349.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 7 is complete.\n",
      "Order:  8\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=8\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320350</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161186877,SC:ATL10.001:161200988,SC:ATL10.001:161078679,SC:ATL10.001:161185873,SC:ATL10.001:161191596,SC:ATL10.001:161192355,SC:ATL10.001:161151704,SC:ATL10.001:161188716,SC:ATL10.001:161166564,SC:ATL10.001:161189004. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.108S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320350\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320350\n",
      "HTTP response from order response URL:  201\n",
      "Data request  8  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161078679:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161192355:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161151704:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161166564:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.824S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320350.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 8 is complete.\n",
      "Order:  9\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=9\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320351</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161159953,SC:ATL10.001:161151321,SC:ATL10.001:161187952,SC:ATL10.001:161138650,SC:ATL10.001:161151700,SC:ATL10.001:161189146,SC:ATL10.001:161191187,SC:ATL10.001:161150864,SC:ATL10.001:161190791,SC:ATL10.001:161080490. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.099S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>10</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320351\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320351\n",
      "HTTP response from order response URL:  201\n",
      "Data request  9  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161187952:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161151700:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161189146:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161150864:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT2.773S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320351.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 9 is complete.\n",
      "Order:  10\n",
      "Request HTTP response:  201\n",
      "Order request URL:  https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL10&version=001&temporal=2018-11-01T00%3A00%3A00Z%2C2018-11-07T23%3A59%3A59Z&time=2018-11-01T00%3A00%3A00%2C2018-11-07T23%3A59%3A59&polygon=130.0%2C65.0%2C180.0%2C65.0%2C180.0%2C88.0%2C130.0%2C88.0%2C130.0%2C65.0&Coverage=%2Fancillary_data%2Fatlas_sdp_gps_epoch%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_fb_length%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_confidence%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_height%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_quality_flag%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fbeam_fb_sigma%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fdelta_time%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fheight_segment_id%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flongitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Flatitude%2C%2Fgt1l%2Ffreeboard_beam_segment%2Fbeam_freeboard%2Fseg_dist_x%2C%2Forbit_info%2Fcycle_number%2C%2Forbit_info%2Frgt%2C%2Forbit_info%2Forbit_number&request_mode=async&page_size=10&token=0A5D25AF-2421-2A2A-B9B8-2955A319E87E&email=david.babb%40umanitoba.ca&bbox=130.0%2C65.0%2C180.0%2C88.0&page_num=10\n",
      "Order request response XML content:  b'<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\\n<eesi:agentResponse xsi:schemaLocation=\"http://eosdis.nasa.gov/esi/rsp/e https://newsroom.gsfc.nasa.gov/esi/8.1/schemas/ESIAgentResponseExternal.xsd\" xmlns=\"\" xmlns:iesi=\"http://eosdis.nasa.gov/esi/rsp/i\" xmlns:ssw=\"http://newsroom.gsfc.nasa.gov/esi/rsp/ssw\" xmlns:eesi=\"http://eosdis.nasa.gov/esi/rsp/e\" xmlns:esi=\"http://eosdis.nasa.gov/esi/rsp\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\\n    <order>\\n        <orderId>5000000320352</orderId>\\n        <Instructions>You may receive an email about your order if you specified an EMAIL address. &lt;br/&gt;&lt;br/&gt;The instructions used to process this order are:  Bounding Box(es)=130.0,65.0,180.0,88.0. Band(s)=/ancillary_data/atlas_sdp_gps_epoch,/gt1l/freeboard_beam_segment/beam_fb_height,/gt1l/freeboard_beam_segment/beam_fb_length,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_confidence,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_height,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_quality_flag,/gt1l/freeboard_beam_segment/beam_freeboard/beam_fb_sigma,/gt1l/freeboard_beam_segment/beam_freeboard/delta_time,/gt1l/freeboard_beam_segment/beam_freeboard/height_segment_id,/gt1l/freeboard_beam_segment/beam_freeboard/longitude,/gt1l/freeboard_beam_segment/beam_freeboard/latitude,/gt1l/freeboard_beam_segment/beam_freeboard/seg_dist_x,/orbit_info/cycle_number,/orbit_info/rgt,/orbit_info/orbit_number. Granule id(s)=SC:ATL10.001:161188454,SC:ATL10.001:161138640,SC:ATL10.001:161149916. Temporal search start=2018-11-01T00:00:00 end=2018-11-07T23:59:59. Email address=david.babb@umanitoba.ca. Processing tool=ICESAT2.</Instructions>\\n    </order>\\n    <contactInformation>\\n        <contactName>NSIDC User Services</contactName>\\n        <contactEmail>nsidc@nsidc.org</contactEmail>\\n    </contactInformation>\\n    <processInfo>\\n        <processDuration>PT0.080S</processDuration>\\n        <subagentId>ICESAT2</subagentId>\\n    </processInfo>\\n    <requestStatus>\\n        <status>processing</status>\\n        <numberProcessed>0</numberProcessed>\\n        <totalNumber>3</totalNumber>\\n    </requestStatus>\\n</eesi:agentResponse>\\n'\n",
      "order ID:  5000000320352\n",
      "status URL:  https://n5eil02u.ecs.nsidc.org/egi/request/5000000320352\n",
      "HTTP response from order response URL:  201\n",
      "Data request  10  is submitting...\n",
      "Initial request status is  processing\n",
      "Status is not complete. Trying again.\n",
      "Retry request status is:  complete_with_errors\n",
      "error messages:\n",
      "['161188454:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " '161138640:NoMatchingData - No data found that matched subset constraints. '\n",
      " 'Exit code 3.',\n",
      " 'PT1.619S',\n",
      " 'ICESAT2']\n",
      "Zip download URL:  https://n5eil02u.ecs.nsidc.org/esir/5000000320352.zip\n",
      "Beginning download of zipped output...\n",
      "Data request 10 is complete.\n"
     ]
    }
   ],
   "source": [
    "# Request data service for each page number, and unzip outputs\n",
    "\n",
    "for i in range(page_num):\n",
    "    page_val = i + 1\n",
    "    print('Order: ', page_val)\n",
    "    subset_params.update( {'page_num': page_val} )\n",
    "    \n",
    "# # Post polygon to API endpoint for polygon subsetting to subset based on original, non-simplified KML file\n",
    "\n",
    "#     shape_post = {'shapefile': open(kml_filepath, 'rb')}\n",
    "#     request = session.post(base_url, params=subset_params, files=shape_post) \n",
    "    \n",
    "# FOR ALL OTHER REQUESTS THAT DO NOT UTILIZED AN UPLOADED POLYGON FILE, USE A GET REQUEST INSTEAD OF POST:\n",
    "    request = session.get(base_url, params=subset_params)\n",
    "    \n",
    "    print('Request HTTP response: ', request.status_code)\n",
    "\n",
    "# Raise bad request: Loop will stop for bad response code.\n",
    "    request.raise_for_status()\n",
    "    print('Order request URL: ', request.url)\n",
    "    esir_root = ET.fromstring(request.content)\n",
    "    print('Order request response XML content: ', request.content)\n",
    "\n",
    "# Look up order ID\n",
    "    orderlist = []   \n",
    "    for order in esir_root.findall(\"./order/\"):\n",
    "        orderlist.append(order.text)\n",
    "    orderID = orderlist[0]\n",
    "    print('order ID: ', orderID)\n",
    "\n",
    "# Create status URL\n",
    "    statusURL = base_url + '/' + orderID\n",
    "    print('status URL: ', statusURL)\n",
    "\n",
    "# Find order status\n",
    "    request_response = session.get(statusURL)    \n",
    "    print('HTTP response from order response URL: ', request_response.status_code)\n",
    "    \n",
    "# Raise bad request: Loop will stop for bad response code.\n",
    "    request_response.raise_for_status()\n",
    "    request_root = ET.fromstring(request_response.content)\n",
    "    statuslist = []\n",
    "    for status in request_root.findall(\"./requestStatus/\"):\n",
    "        statuslist.append(status.text)\n",
    "    status = statuslist[0]\n",
    "    print('Data request ', page_val, ' is submitting...')\n",
    "    print('Initial request status is ', status)\n",
    "\n",
    "# Continue to loop while request is still processing\n",
    "    while status == 'pending' or status == 'processing': \n",
    "        print('Status is not complete. Trying again.')\n",
    "        time.sleep(10)\n",
    "        loop_response = session.get(statusURL)\n",
    "\n",
    "# Raise bad request: Loop will stop for bad response code.\n",
    "        loop_response.raise_for_status()\n",
    "        loop_root = ET.fromstring(loop_response.content)\n",
    "\n",
    "# Find status\n",
    "        statuslist = []\n",
    "        for status in loop_root.findall(\"./requestStatus/\"):\n",
    "            statuslist.append(status.text)\n",
    "        status = statuslist[0]\n",
    "        print('Retry request status is: ', status)\n",
    "        if status == 'pending' or status == 'processing':\n",
    "            continue\n",
    "\n",
    "# Order can either complete, complete_with_errors, or fail:\n",
    "# Provide complete_with_errors error message:\n",
    "    if status == 'complete_with_errors' or status == 'failed':\n",
    "        messagelist = []\n",
    "        for message in loop_root.findall(\"./processInfo/\"):\n",
    "            messagelist.append(message.text)\n",
    "        print('error messages:')\n",
    "        pprint.pprint(messagelist)\n",
    "\n",
    "# Download zipped order if status is complete or complete_with_errors\n",
    "    if status == 'complete' or status == 'complete_with_errors':\n",
    "        downloadURL = 'https://n5eil02u.ecs.nsidc.org/esir/' + orderID + '.zip'\n",
    "        print('Zip download URL: ', downloadURL)\n",
    "        print('Beginning download of zipped output...')\n",
    "        zip_response = session.get(downloadURL)\n",
    "        # Raise bad request: Loop will stop for bad response code.\n",
    "        zip_response.raise_for_status()\n",
    "        with zipfile.ZipFile(io.BytesIO(zip_response.content)) as z:\n",
    "            z.extractall(path)\n",
    "        print('Data request', page_val, 'is complete.')\n",
    "    else: print('Request failed.')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Clean up the folders\n",
    "\n",
    "Extracts the individual files out of the folders and dumps them into the outputs folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Clean up Outputs folder by removing individual granule folders \n",
    "\n",
    "for root, dirs, files in os.walk(path, topdown=False):\n",
    "    for file in files:\n",
    "        try:\n",
    "            shutil.move(os.path.join(root, file), path)\n",
    "        except OSError:\n",
    "            pass\n",
    "        \n",
    "for root, dirs, files in os.walk(path):\n",
    "    for name in dirs:\n",
    "        os.rmdir(os.path.join(root, name))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "List the folders and give the length"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "54"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(os.listdir(path))\n",
    "\n",
    "data = sorted(os.listdir(path))\n",
    "len(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Now to share the data via s3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the terminal type the following to zip the data together: <br>\n",
    "tar -czvf Outputs.tar.gz Outputs\n",
    "\n",
    "And upload the data to the s3 drive. <br>\n",
    "aws s3 cp Outputs.tar.gz s3://pangeo-data-upload-oregon/icesa\n",
    "t2/segtrax/\n",
    "\n",
    "Then the team members can access the data via the following commands: <br>\n",
    "aws s3 cp s3://pangeo-data-upload-oregon/icesat2/segtrax/Outputs.tar.gz . <br>\n",
    "tar -xzvf Outputs.tar.gz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
